package com.javabase.y2022.m02.day0217;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @descriptions: ThirdThread
 * @author: Tom
 * @date: 2022/2/17 下午 08:30
 * @version: 1.0
 */
public class ThirdThread {
    public static void main(String[] args){
        ThirdThread rt = new ThirdThread();
        FutureTask<Integer> task = new FutureTask<Integer>((Callable<Integer>)() -> {
            int i = 0;
            for (; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()
                 + " 的循环变量i的值:" + i);
            }
            return i;
        });
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + " 的循环变量的值:" + i);
            if(i == 20){
                new Thread(task, "有返回值的线程");
            }
        }
        try
        {
            System.out.println("子线程的返回值:" + task.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
